package one.one.eighteen;

public class MyStery {

	public static int mystery(int a, int b) {
		if (b == 0)
			return 0;
		if (b % 2 == 0)
			return mystery(a + a, b / 2);
		return mystery(a + a, b / 2) + a;
	}

	static int theEquivalent(int a, int b) {
		int r = 0;
		while (b > 0) {
			if (b % 2 == 1) {
				r += a;
			}
			a *= 2;
			b /= 2;
		}
		return r;
	}

	public static void main(String[] args) {
		int a = 3;
		int b =11;
		int r = mystery(a, b);
		System.out.println(r);

		int rr = theEquivalent(a, b);
		System.out.println(rr);
	}

}
